<%@ include file="database_ini.jsp"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
	$(document).ready(
			function() {
				$('#refreash').click(function() {
					//alert("refreash...");
                	$(location).attr('href',"index.jsp");
            	});
            	
            	
            	
            	$('#add').click(function() {
	            	$("#CCParameterName").val("CCParameterName");
					$("#StorerkeyFrom").val("0");
					$("#StorerkeyTo").val("ZZZZZZZZZZ");
					$("#SkuFrom").val("0");
					$("#SkuTo").val("ZZZZZZZZZZ");
					$("#ClassFrom").val("0");
					$("#ClassTo").val("ZZZZZZZZZZ");
					$("#ZoneFrom").val("0");
					$("#ZoneTo").val("ZZZZZZZZZZ");
					$("#LocFrom").val("0");
					$("#LocTo").val("ZZZZZZZZZZ");
					$("#XCOORDFROM").val("0");
					$("#XCOORDTO").val("999999");
					$("#YCOORDFROM").val("0");
					$("#YCOORDTO").val("999999");
					$("#ZCOORDFROM").val("0");
					$("#ZCOORDTO").val("999999");
					
					
					
					//alert("CC checked?");
					$("#CC").attr('checked', true);
					//alert("CC checked?" + $("#CC").val());
					//$("#CC").checked = true;
					//alert("CC checked?"+ $("#CC").val());
					
					//alert($("input[name='Serailkey']:checked").val());
					$("input[name='Serailkey']:checked").attr('checked', false);
					//alert($("input[name='Serailkey']:checked").val());
					//$("input[name='Serailkey']:checked").removeAttr("checked");
            	});
            	
            	//$('#Serailkey').change(function() {
            	//$("input[@name='Serailkey']").change(function(){
            	$("input[name='Serailkey']:radio").change(function(){
					//alert($("input[name='Serailkey']:checked").val());
					
					$.ajaxSetup({ cache: false });
					//$.getJSON("qservice.jsp", { Serailkey: $("input[name='Serailkey']:checked").val() }, function(data, state) {
					$.getJSON("query.jsp", { Serailkey: $("input[name='Serailkey']:checked").val() }, function(data, state) {

								/*****************debug/
								alert("data: " + data.StorerkeyFrom);
								/******************/
								
								
								$("#CCParameterName").val(data.CCParameterName);
								$("#StorerkeyFrom").val(data.StorerkeyFrom);
								$("#StorerkeyTo").val(data.StorerkeyTo);
								$("#SkuFrom").val(data.SkuFrom);
								$("#SkuTo").val(data.SkuTo);
								$("#ClassFrom").val(data.ClassFrom);
								$("#ClassTo").val(data.ClassTo);
								$("#ZoneFrom").val(data.ZoneFrom);
								$("#ZoneTo").val(data.ZoneTo);
								$("#LocFrom").val(data.LocFrom);
								$("#LocTo").val(data.LocTo);
								$("#XCOORDFROM").val(data.XCOORDFROM);
								$("#XCOORDTO").val(data.XCOORDTO);
								$("#YCOORDFROM").val(data.YCOORDFROM);
								$("#YCOORDTO").val(data.YCOORDTO);
								$("#ZCOORDFROM").val(data.ZCOORDFROM);
								$("#ZCOORDTO").val(data.ZCOORDTO);
								if(data.DisplaySystemCount == 1){
									$("#DisplaySystemCount").attr('checked', true);
								}
								else{
									$("#DisplaySystemCount").attr('checked', false);
								}
								$("#CC").attr('checked', true);

								/******************/
								//if ( k == -1 ){}
								
							});
					
					
            	});
            	
			});//$(document).ready	
	
	
	function save() {
		$("#myform").attr("action", "save.jsp");
		$("#myform").submit();
	}
	function del() {
		$("#myform").attr("action", "del.jsp");
		$("#myform").submit();
	}
	
	function getURLParameter(name) {
		return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(
				Location.search) || [ , null ])[1]);
	}
	
	$.fn.clearForm = function() {
		// iterate each matching form
		return this.each(function() {
			// iterate the elements within the form
			$(':input', this).each(function() {
				var type = this.type, tag = this.tagName.toLowerCase();
				if (type == 'text' || type == 'password' || tag == 'textarea')
					this.value = '';
				else if (type == 'checkbox' || type == 'radio')
					this.checked = false;
				else if (tag == 'select')
					this.selectedIndex = -1;
			});
		});
	};
</script>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">


<body>
<%
			String status = "";
			if("ok".equals(request.getParameter("status"))){
				String action = request.getParameter("action");
				if("save".equals(action)){
					status = "已成功保存";
				}
				if("del".equals(action)){
					status = "已成功刪除";
				}
				if("pub".equals(action)){
					status = "已成功發佈";
				}
			}
			 %>

	<form id='myform' action="updatetable.jsp" method="post" ALIGN="CENTER" >
		<table ALIGN="CENTER"><tr>
			<td Width="100"><input type="button" id="add" value="新增" /></td>
			<td Width="100"><input type="button" onclick="save()" value="保存" /></td>
			<td Width="100"><input type="button" onclick="del()" value="刪除" /></td>
			<td Width="100"><input type="button" id="refreash" value="刷新" /></td>
			<td Width="100"></td>
			<td Width="100"></td>
			<td Width="100"><% out.print(status); %></td>
			<td Width="100"></td>
			<td Width="100"></td>
		</tr>
		</table>
		
		<table id="mytable"  border = 1 ALIGN="CENTER">
			<tr>
				<th Width="10"></th>
				<th Width="100">貨主起</th>
				<th Width="100">貨主訖</th>
				<th Width="100">貨品起</th>
				<th Width="100">貨品訖</th>
				<th Width="100">品類大項起</th>
				<th Width="100">品類大項訖</th>
				<th Width="100">區起</th>
				<th Width="100">區訖</th>
				<th Width="100">儲位起</th>
				<th Width="100">儲位訖</th>
			</tr>
			
			<% 
			String sql = "select Serailkey, StorerkeyFrom, StorerkeyTo, SkuFrom, SkuTo, ClassFrom, ClassTo, ZoneFrom, ZoneTo, LocFrom, LocTo, XCOORDFROM, XCOORDTO, YCOORDFROM, YCOORDTO, ZCOORDFROM, ZCOORDTO, DisplaySystemCount from CCParameter order by Serailkey";
	
			pstmt = conn.prepareStatement(sql);
	
			ResultSet rs = pstmt.executeQuery();
			boolean firstrecord = true;
			while (rs.next()){
				%>
				<tr>
				<td><input type="radio" id ="Serailkey" name="Serailkey" value="<%=rs.getString("Serailkey")%>" /></td>
				<td><%=rs.getString("StorerkeyFrom") %></td>
				<td><%=rs.getString("StorerkeyTo") %></td>
				<td><%=rs.getString("SkuFrom") %></td>
				<td><%=rs.getString("SkuTo") %></td>
				<td><%=rs.getString("ClassFrom") %></td>
				<td><%=rs.getString("ClassTo") %></td>
				<td><%=rs.getString("ZoneFrom") %></td>
				<td><%=rs.getString("ZoneTo") %></td>
				<td><%=rs.getString("LocFrom") %></td>
				<td><%=rs.getString("LocTo") %></td>
				</tr>
			
				<%
			
			
			}
			conn.close();
			%>
			
			
		</table>
		<BR />
		<BR />
		<table id="detail" ALIGN="CENTER" RULES=NONE FRAME=BOX>
			<tr>
				<td Width="100" COLSPAN=2>循環盤點參數名稱</td>
				<td Width="100"><input id="CCParameterName" type="text" name="CCParameterName" /></td>
				<td Width="100"></td>
				<td Width="100"></td>
				<td Width="100"></td>
				
			</tr>
			<tr>
				<td Width="100"></td>
				<td Width="100">起</td>
				<td Width="100"></td>
				<td Width="100">訖</td>
				<td Width="100"></td>
				<td Width="100"></td>
				
			</tr>
			<tr>
				<td Width="100">貨主</td>
				<td Width="100"><input id="StorerkeyFrom" type="text" name="StorerkeyFrom" /></td>
				<td Width="100"></td>
				<td Width="100"><input id="StorerkeyTo" type="text" name="StorerkeyTo" /></td>
				<td Width="100"></td>
				<td Width="150" ROWSPAN=3 >
				<input type="radio" id = "CC" name="type" value="CC" />循環盤點<br />
				<input type="radio" name="type" value="ITRN" />異動盤點<br />
				<input type="radio" name="type" value="EMPTY" />空庫位盤點<br />
				</td>
			</tr>
			<tr>
				<td Width="100">貨品</td>
				<td Width="100"><input id="SkuFrom" type="text" name="SkuFrom" /></td>
				<td Width="100"></td>
				<td Width="100"><input id="SkuTo" type="text" name="SkuTo" /></td>
				<td Width="100"></td>
			</tr>
			<tr>
				<td Width="100">品類大項</td>
				<td Width="100"><input id="ClassFrom" type="text" name="ClassFrom" /></td>
				<td Width="100"></td>
				<td Width="100"><input id="ClassTo" type="text" name="ClassTo" /></td>
				<td Width="100"></td>
			</tr>
			<tr>
				<td Width="100">區</td>
				<td Width="100"><input id="ZoneFrom" type="text" name="ZoneFrom" /></td>
				<td Width="100"></td>
				<td Width="100"><input id="ZoneTo" type="text" name="ZoneTo" /></td>
				<td Width="100"></td>
				<td Width="100"></td>
			</tr>
			<tr>
				<td Width="100">儲位</td>
				<td Width="100"><input id="LocFrom" type="text" name="LocFrom" /></td>
				<td Width="100"></td>
				<td Width="100"><input id="LocTo" type="text" name="LocTo" /></td>
				<td Width="100"></td>
				<td Width="100"></td>
			</tr>
			<tr>
				<td Width="100">X坐標</td>
				<td Width="100"><input id="XCOORDFROM" type="text" name="XCOORDFROM" /></td>
				<td Width="100"></td>
				<td Width="100"><input id="XCOORDTO" type="text" name="XCOORDTO" /></td>
				<td Width="100"></td>
				<td Width="100"></td>
			</tr>
			<tr>
				<td Width="100">Y坐標</td>
				<td Width="100"><input id="YCOORDFROM" type="text" name="YCOORDFROM" /></td>
				<td Width="100"></td>
				<td Width="100"><input id="YCOORDTO" type="text" name="YCOORDTO" /></td>
				<td Width="100"></td>
				<td Width="100"></td>
			</tr>
			<tr>
				<td Width="100">Z坐標</td>
				<td Width="100"><input id="ZCOORDFROM" type="text" name="ZCOORDFROM" /></td>
				<td Width="100"></td>
				<td Width="100"><input id="ZCOORDTO" type="text" name="ZCOORDTO" /></td>
				<td Width="100"></td>
				<td Width="100"></td>
			</tr>
		<tr><td Width="100">顯示系統量<input type="checkbox" id ="DisplaySystemCount" name="DisplaySystemCount" value="1" /><br /></td>
		<td Width="100"></td>
		<td Width="100"></td>
		<td Width="100"></td>
		<td Width="100"></td>
		<td Width="100"></td>
		</tr>
		<tr>
		<td Width="100"></td>
		<td Width="100"></td>
		<td Width="100"></td>
		<td Width="100"><input type="submit" value="發佈" /></td>
		<td Width="100"></td>
		<td Width="100"></td>
		</tr>
		</table>
	</form>
</body>
</html>

